# @Time    :2025/4/25 10:01
# class Solution:
#     def isIsomorphic(self, s: str, t: str) -> bool:
#         if len(s) != len(t):
#             return False
#
#         s_to_t = {}
#         t_to_s = {}
#
#         for char_s, char_t in zip(s, t):
#             # 检查s中的字符是否已经映射到不同的字符
#             if char_s in s_to_t:
#                 if s_to_t[char_s] != char_t:
#                     return False
#
#             else:
#                 s_to_t[char_s] = char_t
#
#             # 检查t中的字符是否已经由不同的字符映射而来
#             if char_t in t_to_s:
#                 if t_to_s[char_t] != char_s:
#                     return False
#             else:
#                 t_to_s[char_t] = char_s
#
#         return True





class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        if len(s) != len(t):
            return False
        # 定义两个字典 用来存放遍历后的数据
        s1 = {}
        s2 = {}
        for i, j in zip(s, t):  # 用拉链函数zip
            if i in  s1:
                if s1[i] != j:
                    return False
            s1[i] = j

            if j in  s2:
                if s2[j] != i:
                    return False
            s2[j] = i

        return True



s=Solution()
print(s.isIsomorphic("eg", "akk"))